package top.wangjingxin.base;


import static java.lang.System.currentTimeMillis;

public class Test {
    static class D {
        String a;

        D(String a) {
            this.a = a;
        }
    }

    static void test1() {
        long start = currentTimeMillis();
        StringBuilder sb = new StringBuilder("a");
        for (int i = 0; i < 60000; i++) {
            sb.append("a");
        }
        System.out.println(currentTimeMillis() - start);
    }

    static void test2() {
        long start = currentTimeMillis();
        String buffer = "a";
        for (int i = 0; i < 60000; i++) {
            buffer = new StringBuilder(i).append("b").toString();
        }
        System.out.println(currentTimeMillis() - start);
    }

    static void test3() {
        long start = currentTimeMillis();
        String buffer = "a";
        for (int i = 0; i < 60000; i++) {
            buffer += "b";
        }
        System.out.println(currentTimeMillis() - start);
    }

    static void test4() {
        long start = currentTimeMillis();
        for (int i = 0; i < 60000; i++) {
            //D d = new D(i+"a");
            D d = new D(new StringBuffer(i).append("a").toString());

        }
        System.out.println(currentTimeMillis() - start);
    }

    public static void main(String[] args) {
        test2();
        test3();
        test4();
    }
}
